package com.parse.starter.order;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.parse.bean.ProduceResultDTO;
import com.parse.contract.Args;
import com.parse.starter.R;
import com.parse.starter.R.id;
import com.parse.starter.R.layout;

/**
 * 
 * 選擇商品控制器 商品數量控制
 * 
 * @author Andy
 * 
 */
public class ItemActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.item_lay);

		final EditText itemNum = (EditText) ItemActivity.this
				.findViewById(R.id.itemNum);

		final Bundle bundle = this.getIntent().getExtras();

		final ProduceResultDTO info = (ProduceResultDTO) bundle
				.getSerializable(Args.BEAN_NAME);

		((TextView) this.findViewById(R.id.name)).setText(info.getName());// 名稱
		((EditText) this.findViewById(R.id.itemNum)).setText(info.getNum());// 購買數量

		this.findViewById(R.id.addItem).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {

						Intent intent = new Intent();
						final Bundle bundle = new Bundle();
						final String no = itemNum.getText().toString();
						info.setNum(no);
						bundle.putSerializable(Args.BEAN_NAME, info);
						intent.putExtras(bundle);

						setResult(RESULT_OK, intent);
						finish();
					}
				});

		this.findViewById(R.id.backBtn).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						setResult(RESULT_OK);
						finish();

					}
				});
	}
}
